package com.lagou.work.controller;

import com.lagou.work.dao.ResumeDao;
import com.lagou.work.pojo.Resume;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/resume")
public class ResumeController {
    //http://localhost:8080/sss-work/resume/login?id=1&name=张三
    @Autowired
    private ResumeDao resumeDao;

    @RequestMapping(value = "/login" )
    @ResponseBody
    public List<Resume> login(int id, String name) throws Exception {
        System.out.println("id：" + id + "，姓名：" + name);
        List<Resume> resumeList = resumeDao.findAll();
        return resumeList;
    }

    @RequestMapping(value = "/insertOrUpdate")
    @ResponseBody
    public Resume insertOrUpdate(@RequestBody Resume resume) throws Exception {
        Resume result = resumeDao.save(resume);
        return result;
    }

    @RequestMapping(value = "/delete")
    @ResponseBody
    public String delete(@PathVariable("id") long id) throws Exception {
        resumeDao.deleteById(id);
        return "成功";
    }

}
